package com.ruoyi.school.utils;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.school.domain.Student;
import com.ruoyi.school.service.StudentService;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

/*
 * @Author Lin
 * @Description 一些通用的信息查询类
 * @Date 2025/5/26
 */
public class CommonUtils {

    private static StudentService studentService;

    // 手动注入 StudentService
    public static void init(StudentService service) {
        studentService = service;
    }

    /**
     * 获取学生信息
     **/
    public static Student getStudent()
    {
        try
        {
            SysUser user = getLoginUser().getUser();
            Student student = studentService.selectByUserId(user.getUserId());
            return student;
        }
        catch (Exception e)
        {
            throw new ServiceException("获取学生信息异常", HttpStatus.ERROR);
        }
    }
}
